package com.xyzboom.compiler.compiler.lexer

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.annotation.JsonNaming
import com.xyzboom.compiler.NoArg
import com.xyzboom.compiler.fa.DFA
import com.xyzboom.compiler.fa.regex.parseRegex
import com.xyzboom.compiler.fa.toDFA

/**
 * Lexer rule
 *
 * @constructor Create empty Lexer rule
 */
@NoArg
class LexerRule {
    val name: String
    val typeName: String
    val dfa: DFA<Int, Char>
    var greedy: Boolean = true

    constructor(name: String, typeName: String, dfa: DFA<Int, Char>) {
        this.name = name
        this.typeName = typeName
        this.dfa = dfa
    }


    constructor(name: String, typeName: String, regex: String) {
        this.name = name
        this.typeName = typeName
        dfa = parseRegex(regex).toDFA()
    }


    override fun toString(): String {
        return "LexerRule(name='$name', typeName='$typeName'${if (!greedy) ", no greedy" else ""})"
    }
}